package com.boot.unity.api.wx.service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import okhttp3.*;
import org.springframework.stereotype.Service;

@Service
public class SendJsService {

    public String cardNolist(String url) throws Exception{
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("text/plain");
        RequestBody body = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
                .url(url).method("POST", body).build();
        Response response = client.newCall(request).execute();
        String dataJson = response.body().string();
        JSONObject json = JSONObject.parseObject(dataJson);
        if(StringUtil.isEmpty(json.getString("data"))){
            return "";
        }else{
            return json.getString("data");
        }
    }

    public String getStuByCardNo(String url,String json) throws Exception{
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, json);
        // "http://localhost:9001/jsapi/stuDetail"
        Request request = new Request.Builder()
                .url(url).method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        String dataJson = response.body().string();
        JSONObject jsonData = JSONObject.parseObject(dataJson);
        return jsonData.getString("data");
    }
}
